﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;




public partial class Admin_ChangePassword : System.Web.UI.Page
{
    MembershipUser user;
    protected void Page_Load(object sender, EventArgs e)
    {
        //(!IsPostBack)
        //{
        //    LabelErrorMessage.Visible=false;
        //}        
    }


    protected void ChangePasswordPushButton_Click(object sender, EventArgs e)
    {


    }
    protected void CancelPushButton_Click(object sender, EventArgs e)
    {
        Response.Redirect("~/home/Dashboard.aspx");

    }
    protected void csvEmail_ServerValidate(object source, ServerValidateEventArgs args)
    {


    }
    protected Boolean Human_Validate()
    {
        string EncodedResponse = Request.Form["g-Recaptcha-Response"];
        bool IsCaptchaValid = (ReCaptchaClass.Validate(EncodedResponse) == "true" ? true : false);

        if (IsCaptchaValid)
        {
            return true;
            //Valid Request
        }
        else
        {
            return false;
        }
    }
    protected void ChangePassword1_ChangingPassword(object sender, LoginCancelEventArgs e)
    {
        if (Human_Validate())
        {
            if (ChangePassword1.CurrentPassword == ChangePassword1.NewPassword)
            {
                //    string username = Convert.ToString(Session["UserName"]);
                //    if (username != null)
                //    {
                //        user = Membership.GetUser(Membership.GetUserNameByEmail(username.Trim()));
                //        bool checkpasschange = user.ChangePassword(ChangePassword1.CurrentPassword, ChangePassword1.NewPassword);
                //        if (checkpasschange)
                //        {
                //            Membership.UpdateUser(user);
                //            // ChangePassword1.SuccessPageUrl = "~/home/PasswordChanged.aspx"; 
                //            Response.Redirect("~/home/PasswordChanged.aspx");

                //        }
                //        else
                //        {
                //            ChangePassword1.ChangePasswordFailureText = " Old Password is not correct so cannot update try again";
                //        }

                //    }
                //    else
                //    {

                //    }

                //}
                //else
                //{
                //    ChangePassword1.ChangePasswordFailureText = "Old password and new password cannot be same kindly re-enter";
                //}
                LabelErrorMessage.Visible = true;
                LabelErrorMessage.Text = "Old Password and New Password Cannot be Same Kindly try Again";
                //ClientScript.RegisterStartupScript(this.GetType(), "HideLabel", "<script type=\"text/javascript\">setTimeout(\"document.getElementById('" + LabelErrorMessage.ClientID + "').style.display='none'\",4000)</script>");


                e.Cancel = true;
                //ChangePassword1.SuccessPageUrl = "~/home/PasswordChanged.aspx";
                //Response.Redirect("~/home/PasswordChanged.aspx");
            }
            else { LabelErrorMessage.Visible = false; }

            //private void dislpaymessage()
            //{
            //    Label displaylabel = new Label();
            //    displaylabel.Text = "New Password is same as Old Password Please Set new password";
            //    div1.Controls.Add(displaylabel);
            //}
        }
        else
        {
            LabelErrorMessage.Visible = true;
            LabelErrorMessage.Text = "Please verify that you are not a robot.";
            e.Cancel = true;
        }
    }
}